<?php

// TITLE: interest
// FILE: interest.php
// AUTHOR: dantira
// CREATED: Mar 21, 2015, 4:57:42 PM
?>

		public function createInterest($id, $typeId, $title, $description) {
			global $con;
			$sql = 'INSERT INTO interest (id, type_id, title, description) VALUES (' . $id . ', ' . $typeId . ', ' . $title . ', ' . $description . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readInterest($id) {
			global $con;
			$sql = 'SELECT * FROM interest WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$interest = new Interest();
				$interest->setId($result[0]);
				$interest->setTypeId($this->readType($result[1]));
				$interest->setTitle($result[2]);
				$interest->setDescription($result[3]);
			} else {
				$interest = false;
			}
			return $interest;
		}// end function

		public function updateInterest($id, $typeId, $title, $description) {
			global $con;
			$sql = 'UPDATE interest SET type_id = ' . $type_id . ', title = ' . $title . ', description = ' . $description . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteInterest($id) {
			global $con;
			$sql = 'DELETE FROM interest WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listInterest() {
			global $con;
			$sql = 'SELECT * FROM interest';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$interests = array();
				while ($result = mysqli_fetch_array($results)) {
					$interest = new Interest();
					$interest->setId($result[0]);
					$interest->setTypeId($this->readType($result[1]));
					$interest->setTitle($result[2]);
					$interest->setDescription($result[3]);
					$interests[] = $interest;
				}// end while
			} else {
				$interests = false;
			}
			return $interests;
		}// end function

		// interest_type // --------------------

		public function createInterestType($id, $title, $code, $description) {
			global $con;
			$sql = 'INSERT INTO interest_type (id, title, code, description) VALUES (' . $id . ', ' . $title . ', ' . $code . ', ' . $description . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readInterestType($id) {
			global $con;
			$sql = 'SELECT * FROM interest_type WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$interestType = new InterestType();
				$interestType->setId($result[0]);
				$interestType->setTitle($result[1]);
				$interestType->setCode($result[2]);
				$interestType->setDescription($result[3]);
			} else {
				$interestType = false;
			}
			return $interestType;
		}// end function

		public function updateInterestType($id, $title, $code, $description) {
			global $con;
			$sql = 'UPDATE interest_type SET title = ' . $title . ', code = ' . $code . ', description = ' . $description . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteInterestType($id) {
			global $con;
			$sql = 'DELETE FROM interest_type WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listInterestType() {
			global $con;
			$sql = 'SELECT * FROM interest_type';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$interestTypes = array();
				while ($result = mysqli_fetch_array($results)) {
					$interestType = new InterestType();
					$interestType->setId($result[0]);
					$interestType->setTitle($result[1]);
					$interestType->setCode($result[2]);
					$interestType->setDescription($result[3]);
					$interestTypes[] = $interestType;
				}// end while
			} else {
				$interestTypes = false;
			}
			return $interestTypes;
		}// end function

		// interested_in // --------------------

		public function createInterestedIn($volunteerId, $interestId) {
			global $con;
			$sql = 'INSERT INTO interested_in (volunteer_id, interest_id) VALUES (' . $volunteerId . ', ' . $interestId . ')';
			$this->open();
			$result = mysqli_query($con, $sql);
			$id = ($result) ? mysqli_insert_id($con) : $result;
			$this->close();
			return $id;
		}// end function

		public function readInterestedIn($id) {
			global $con;
			$sql = 'SELECT * FROM interested_in WHERE id = ' . $id;
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$result = mysqli_fetch_array($results);
				$interestedIn = new InterestedIn();
				$interestedIn->setVolunteerId($this->readVolunteer($result[0]));
				$interestedIn->setInterestId($this->readInterest($result[1]));
			} else {
				$interestedIn = false;
			}
			return $interestedIn;
		}// end function

		public function updateInterestedIn($volunteerId, $interestId) {
			global $con;
			$sql = 'UPDATE interested_in SET volunteer_id = ' . $volunteer_id . ', interest_id = ' . $interestId . ' WHERE id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function deleteInterestedIn($id) {
			global $con;
			$sql = 'DELETE FROM interested_in WHERE volunteer_id = ' . $id;
			$this->open();
			$result = mysqli_query($con, $sql);
			$this->close();
			return $result;
		}// end function

		public function listInterestedIn() {
			global $con;
			$sql = 'SELECT * FROM interested_in';
			$this->open();
			$results = mysqli_query($con, $sql);
			$this->close();
			if ($results) {
				$interestedIns = array();
				while ($result = mysqli_fetch_array($results)) {
					$interestedIn = new InterestedIn();
					$interestedIn->setVolunteerId($this->readVolunteer($result[0]));
					$interestedIn->setInterestId($this->readInterest($result[1]));
					$interestedIns[] = $interestedIn;
				}// end while
			} else {
				$interestedIns = false;
			}
			return $interestedIns;
		}// end function

